package com.example.meimessage.favorite;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;

import com.example.meimessage.R;

public class GridViewCheckAdapter extends BaseAdapter{
	private ArrayList<HashMap<String,Object>> list=new ArrayList<HashMap<String,Object>>();
	private Context context=null;
	private static HashMap<Integer, Boolean> isSelected= new HashMap<Integer, Boolean>();
	public GridViewCheckAdapter(ArrayList<HashMap<String,Object>> list,Context context){
		this.list=list;
		this.context=context;
		for (int i = 0; i < list.size(); i++) {
			getIsSelected().put(i, false);
		}
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder=null;
		if (convertView == null) {
			holder=new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.favorite_more_gridview_mark, null);

			holder.checkedTextView=(CheckedTextView) convertView.findViewById(R.id.gridView_mark_item);
			
			convertView.setTag(holder);
		}
		else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.checkedTextView.setText(list.get(position).get("gridView").toString());
		holder.checkedTextView.setChecked(getIsSelected().get(position));
		return convertView;
	}
	public static HashMap<Integer, Boolean> getIsSelected() {
		return isSelected;
	}
	public static class ViewHolder
	{
		CheckedTextView checkedTextView;
	}

}
